package mn.idax.exchange.otc.service.impl;

import mn.idax.exchange.common.CalendarUtil;
import mn.idax.exchange.otc.entity.OTCOrder;
import mn.idax.exchange.otc.entity.OTCOrderLog;
import mn.idax.exchange.otc.mapper.OTCOrderLogMapper;
import mn.idax.exchange.otc.service.OTCOrderLogService;
import mn.idax.exchange.otc.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Create by jack_huang on 2018/8/19
 */
@Service
public class OTCOrderLogServiceImpl implements OTCOrderLogService {

    @Autowired
    private OTCOrderLogMapper otcOrderLogMapper;

    //插入订单日志 调用之前  必须判断订单是否存在
    @Override
    public int insertOtcOrderLog(OTCOrder order, Integer beChangedOrderState) {

        OTCOrderLog otcOrderLog = new OTCOrderLog();

        otcOrderLog.setOrderid(order.getId());
        otcOrderLog.setNumber(order.getNumber());
        otcOrderLog.setType(order.getType());
        otcOrderLog.setOrderstate(beChangedOrderState);
        otcOrderLog.setCreatesource(order.getOrdersource());
        otcOrderLog.setCreator(1);//TODO
        otcOrderLog.setCreatetime(DateUtils.getCalendarToDate(CalendarUtil.getUTCDate(new Date())));
        otcOrderLog.setUpdatetime(otcOrderLog.getCreatetime());

        return otcOrderLogMapper.insertSelective(otcOrderLog);
    }
}
